//package com.osi.service.impl;
//
//import cn.hutool.core.lang.Validator;
//import com.osi.bean.Student;
//import com.osi.exception.BaseException;
//import com.osi.service.StudentService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.autoconfigure.security.SecurityProperties;
//import org.springframework.security.core.authority.SimpleGrantedAuthority;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.stereotype.Service;
//
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * 用户验证处理
// *
// * @author lixin
// */
//@Slf4j
//@Service
//public class UserDetailsServiceImpl implements UserDetailsService {
//
//    @Autowired
//    private StudentService studentService;
//
//
//    @Override
//    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//        Student student = studentService.selectStudentByUsername(username);
//        if (Validator.isNull(student)) {
//            log.info("登录用户：{} 不存在.", username);
//            throw new UsernameNotFoundException("登录用户：" + username + " 不存在");
//        } else if (student.getStatus() == 0) {
//            log.info("登录用户：{} 已被停用.", username);
//            throw new BaseException("对不起，您的账号：" + username + " 已停用");
//        }
//
//        return createLoginUser(student);
//    }
//
//    public UserDetails createLoginUser(Student student) {
//        List<SimpleGrantedAuthority> list = new ArrayList<>();
//        String role = "ROLE_STUDENT";
//        list.add(new SimpleGrantedAuthority(role));
//        return new org.springframework.security.core.userdetails.User(student.getUsername(), student.getPassword(), list);
//    }
//}
